package com.probox.common.entity.service.product.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.probox.common.core.constant.CachePrefix;
import com.probox.common.core.enums.DataStatus;
import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.redis.service.RedisService;
import com.probox.product.api.domain.ProductBuyersshowVo;
import com.probox.common.entity.domain.product.vo.ProductBuyersshowQuery;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.probox.common.entity.mapper.product.ProductBuyersshowMapper;
import com.probox.common.entity.domain.product.ProductBuyersshow;
import com.probox.common.entity.service.product.IProductBuyersshowService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 商品买家修信息Service业务层处理
 *
 * @author usoft
 * @date 2021-09-01
 */
@Service
@Transactional
public class ProductBuyersshowServiceImpl extends ServiceImpl<ProductBuyersshowMapper, ProductBuyersshow> implements IProductBuyersshowService {
    @Autowired
    private ProductBuyersshowMapper productBuyersshowMapper;

    @Autowired
    private RedisService redisService;

    /**
     * 查询商品买家修信息
     *
     * @param buyersshowUid 商品买家修信息ID
     * @return 商品买家修信息
     */
    @Override
    public ProductBuyersshow selectProductBuyersshowById(Long buyersshowUid) {
        return this.getById(buyersshowUid);
    }

    @Override
    public ProductBuyersshowVo get(ProductBuyersshowQuery query) {
        String key = CachePrefix.PRODUCT_BUYERSSHOW + query.getBuyersshowUid();
        ProductBuyersshowVo productBuyersshowVo = redisService.get(key, ProductBuyersshowVo.class);
        if(ObjectUtil.isEmpty(productBuyersshowVo)){
            productBuyersshowVo = productBuyersshowMapper.get(query);
            redisService.set(key,productBuyersshowVo,1L, TimeUnit.DAYS);
        }
        return productBuyersshowVo;
    }

    /**
     * 查询商品买家修信息列表
     *
     * @param query 商品买家修信息
     * @return 商品买家修信息
     */
    @Override
    public List<ProductBuyersshowVo> queryList(ProductBuyersshowQuery query) {
        return productBuyersshowMapper.queryList(query);
    }

    /**
     * 新增商品买家修信息
     *
     * @param productBuyersshow 商品买家修信息
     * @return 结果
     */
    @Override
    public boolean insertProductBuyersshow(ProductBuyersshow productBuyersshow) {

        return this.save(productBuyersshow);
    }


    @Override
    
    public boolean insertProductBuyersshows(ProductBuyersshow productBuyersshow) {

        return this.save(productBuyersshow);
    }


    /**
     * 修改商品买家修信息
     *
     * @param productBuyersshow 商品买家修信息
     * @return 结果
     */
    @Override
    public boolean updateProductBuyersshow(ProductBuyersshow productBuyersshow) {
        productBuyersshow.setUpdateUid(SecurityUtils.getUserId());
        productBuyersshow.setUpdateName(SecurityUtils.getUsername());
        productBuyersshow.setUpdateTime(DateUtil.date());
        redisService.deleteObject(CachePrefix.PRODUCT_BUYERSSHOW + productBuyersshow.getBuyersshowUid());
        return this.updateById(productBuyersshow);
    }

    /**
     * 批量删除商品买家修信息
     *
     * @param buyersshowUids 需要删除的商品买家修信息ID
     * @return 结果
     */
    @Override
    public boolean deleteProductBuyersshowByIds(Long[] buyersshowUids) {
        UpdateWrapper<ProductBuyersshow> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("BUYERSSHOW_UID", Arrays.asList(buyersshowUids));
        updateWrapper.eq("PLATFORM_UID", SecurityUtils.getPlatformId());
        updateWrapper.set("DATA_STATUS", DataStatus.delete.getKey());
        updateWrapper.set("UPDATE_UID", SecurityUtils.getUserId());
        updateWrapper.set("UPDATE_NAME", SecurityUtils.getUsername());
        updateWrapper.set("UPDATE_TIME", DateUtil.date());
        return this.removeByIds(Arrays.asList(buyersshowUids));
    }


}
